
ttt = {}
base_table = {}
eye_base_table = {}

# 对于无癞子 万,条,筒

def add(key,value):
    if key % 3 == 0:
        if key not in base_table:
            base_table.setdefault(key, [])
        base_table[key] = 0
    else:
        if key not in eye_base_table:
            eye_base_table.setdefault(key, [])
        eye_base_table[key] = value


def add_table(e_list,value):
    key_num = 0
    for i in range(0,9):
        key_num = key_num * 10 + e_list[i]

    if key_num in ttt:
        return

    ttt.setdefault(key_num, True)

    # key = 0
    # for i in range(0,9):
    #     if e_list[i] > 0:
    #         key = key * 10 + e_list[i]
    #     else:
    #         if key > 0:
    #             add(key,value)
    #             key = 0

    # if key > 0:
    #     add(key,value)
    add(key_num,value)


def gen_table_sub(e_list,count,value):
    for i in range(0,16):
        if i < 9:
            if e_list[i] > 1 : continue
            e_list[i] += 3
        else:
            index = i - 9
            if e_list[index] >= 4 or e_list[index + 1] >= 4 or e_list[index + 2] >= 4:
                continue
            e_list[index] += 1
            e_list[index + 1] += 1
            e_list[index + 2] += 1

        add_table(e_list,value)

        if count < 3:
            gen_table_sub(e_list,count + 1,value)

        if i < 9:
            e_list[i] -= 3
        else:
            index = i - 9
            e_list[index] -= 1
            e_list[index + 1] -= 1
            e_list[index + 2] -= 1

#   4bit  0: 对子的数量(0～7)
#   4bit  4: 对子的值(0 ~ 9)
#   4bit  8: 最大的百搭值(0 ~ 9)
#   4bit 12: 百搭的值1(0～9)
#   4bit 16: 百搭的值2(0～13)
#   4bit 20: 百搭的值3(0～13)
#   4bit 24: 百搭的值4(0～13)
def get_base_table():
    e_list = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    gen_table_sub(e_list,0,0)

def gen_eye_base_table():
    e_list = [0, 0, 0, 0, 0, 0, 0, 0, 0]

    for i in range(0,9):
        e_list[i] = 2
        value = 1 + ((i + 1) << 4) + (0 << 8)
        add_table(e_list,value)
        gen_table_sub(e_list,0,value)
        e_list[i] = 0


get_base_table()
gen_eye_base_table()

with open("E:\PythonWorkSpace\generate_list_hu\\tables\\base_table.txt","w") as file:
    for s in base_table:
        # ss = "baseTable.insert(std::pair<uint32_t,bool>({key},true));".format(key = s)
        ss = "{key},{value}".format(key = s,value= base_table[s])
        file.writelines(ss + "\n")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\eye_base_table.txt","w") as file:
    for s in eye_base_table:
        # ss = "eyeBaseTable.insert(std::pair<uint32_t,bool>({key},true));".format(key = s)
        ss = "{key},{value}".format(key = s,value= eye_base_table[s])
        file.writelines(ss + "\n")








